#include "dlgrename.h"
#include "ui_dlgrename.h"

#include "qappwidget.h"

DlgRename::DlgRename(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DlgRename)
{
    ui->setupUi(this);
}

DlgRename::DlgRename(QString &name, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DlgRename),
    m_descr(name)
{
    ui->setupUi(this);
    ui->lineEdit_descr->setText(m_descr);
    ui->lineEdit_descr->selectAll();
    m_descr_cache = name;

}

DlgRename::~DlgRename()
{
    delete ui;
}

void DlgRename::on_lineEdit_descr_textEdited(const QString &text)
{
    if ( text.size() != 0 )
    {
        m_descr = text;
        QAppWidget::lineEditErr(QAppWidget::le_err_ok,ui->label_descr);
    }
    else
    {
       QAppWidget::lineEditErr(QAppWidget::le_err,ui->label_descr,
                   "La descrizione non deve essere vuota !!!");
    }
}

void DlgRename::on_buttonBox_accepted()
{

}

void DlgRename::on_buttonBox_rejected()
{
    m_descr = m_descr_cache;
}

QString DlgRename::getDescr() const
{
    return m_descr;
}
